import {Base} from '../../utils/base.js'
const base = new Base();
Page({
  data: {
    items: [
      { name: '18会展班', value: '18会展班' },
      { name: '18工艺班', value: '18工艺班'},
      { name: '18计美1班', value: '18计美1班' },
      { name: '18计美2班', value: '18计美2班' },
      { name: '18配饰班', value: '18配饰班' },
      { name: '18陶艺班', value: '18陶艺班' },
    ],
    date: '',
    isShow: false
  },
  radioChange(e) {
    this.setData({
      date: e.detail.value
    })
  },
  update () {
    let data = this.data.date;
    if (!data) {
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: '请选择您需要投票的班级'
      })
      return
    } else {
      var params = {
        url: 'tp/getTpAdd',
        type: 'post',
        data: { date: this.data.date },
        sCallback: res => {
          wx.setStorageSync('show', true)
          this.setData({
            isShow: true
          })
          if (res.errorCode == 0) {
            wx.showToast({
              title: '投票成功',
              icon: 'success',
              duration: 2000
            })
          }
        }
      }
      // 调用封装的request 调用api请求函数
      base.request(params);
    }
    
  },
  onLoad () {
    var params = {
      url: 'tp/getTpData',
      sCallback: res => {
        if (!res) {
          this.setData({
            isShow: false
          })
        } else {
          wx.setStorageSync('show', true)
          this.setData({
            isShow: true
          })
        }
      }
    }
    // 调用封装的request 调用api请求函数
    base.request(params);
  },
  onShow () {
    this.setData({
      isShow: wx.getStorageSync('show')
    })
  },
  onShareAppMessage: function (option) {
    wx.showShareMenu({
      withShareTicket: true
    })
  }
})
